<extend name="common:commonNewerTemplate" />
<block name="main_content">
<div id="content">
	<style>
		.addressSelect{
			color: #000;
		    float: right;
		    font-size: 20px;
		    font-weight: bold;
		    line-height: 20px;
		    opacity: 0.2;
		    text-shadow: 0 1px 0 #fff;
		}
		.alert .addressSelect{
			line-height: 20px;
		    position: relative;
		    right: -21px;
		    top: -2px;
		}
	</style>
	<div id="content-header">
		<div id="breadcrumb">
			<a class="tip-bottom" href="#"
				data-original-title="Go to Home"><i class="icon-home"></i> 首页</a>
			<a href="#">经销商</a> <a class="current" href="#">经销商订单录入2 - 选择收货地址与商品</a>
		</div>
	</div>

    <div id="">


        <div class="container-fluid" id="biz_dealer" dealer_id="{$dealer_info_en.dealer_id}">
            <div class="row-fluid">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-title">
						<span class="icon"> <i class="icon-info-sign"></i>
						</span>
                            <h5>经销商信息</h5>
                        </div>
                        <div class="widget-content nopadding" >
                            <br />
                            <div class="controls controls-row" style="text-align:center;">
                                <label style="display: inline; margin-left: 10px;">经销商编号：</label><input id="dealer_id" value="{$dealer_info_en.dealer_id}" style="width:200px;height:25px;" type="text" class="m-wrap"  readonly="readonly"/>
                                <label style="display: inline; margin-left: 10px;">经销商姓名：</label><input id="dealer_name" value="{$dealer_info_en.dealer_name}" style="width:200px;height:25px;" type="text" class="m-wrap" readonly="readonly"/>
                                <label style="display: inline; margin-left: 10px;">默认返点：</label><input id="discount_rate" value="{$dealer_info_en.discount_rate}" style="width:200px;height:25px;" type="text" class="m-wrap" readonly="readonly"/>
                                <label style="display: inline; margin-left: 10px;">法人代表：</label><input id="leal_person" value="{$dealer_info_en.Leal_person}" style="width:200px;height:25px;" type="text" class="m-wrap" readonly="readonly"/>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="row-fluid" id="address" select_address_id="">
                <div class="span12">
                    <div class="widget-box">
                        <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
                            <h5>收货地址选择</h5>
                            <a href='/address/addressinfo?user_id={$dealer_info_en.user_id}&dealer_channel=1' class="btn btn-primary btn-mini" id='add_address_href'>新增地址</a>
                        </div>
                        <div id="address_lst_div" class="">
                            <volist name="lst_user_address_en" id="user_address_en">
                            <div style="padding: 5px; cursor: pointer; width: 80%; " address_id="{$user_address_en.address_id}" class="biz_address_div">
                                <div style="margin-bottom:5px;height: 120px;width: 100%;" class="alert alert-success alert-block">
                                    <a class="addressSelect" href="#">未选择</a>
                                    <h4 class="alert-heading">{$user_address_en.consignee_name}【{$user_address_en.consignee_cellphone}】</h4>
                                    <span style="font-size:16px;">{$user_address_en.consignee_province} {$user_address_en.consignee_city} {$user_address_en.consignee_district} {$user_address_en.consignee_address}</span>
                                </div>
                            </div>
                            </volist>
                        </div>
                    </div>

                </div>
            </div>
        </div>


        <div class="row-fluid">
            <div class="span12">
                <div class="widget-box">
                    <div class="widget-title"> <span class="icon"> <i class="icon-th"></i> </span>
                        <h5>商品选择</h5>
                    </div>
                    <div class="widget-content">
                        <ul class="recent-posts">
                            <volist name="lst_sku" id="product">
                                <li>
                                    <div class="article-post">
                                        <div class="fr">
                                            <a href="#" class="icon-plus"></a>
                                            <input sku_id='{$product.sku_id}' is_rebate='{$product.is_rebate}' class="qty" type="text" style="width:40px;" value="0"/>
                                            <a href="#" class="icon-minus"></a>
                                        </div>
                                        <div style="" class="fr">
                                            售&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;价：￥<span class="sale_price" style="text-decoration:line-through;">{$product.sale_price}</span><br>
                                            折扣价格：￥<span class="discount_price" style="color:red;">{$product.sale_price}</span><br>
                                        </div>
                                        <span style="color:red;" class="user-info">
      						<if condition="($product.is_rebate eq '0')">
      						  正价商品，无返点
      						<else/>
     						 </if>

     					<if condition="($product.is_rebate eq '1')">
      						  参与返点
      						<else/>
     						 </if>
                </span>
                                        <div style="font-size:16px;font-weight:bold">{$product.sku_name} </div>
                                    </div>
                                </li>
                            </volist>
                            <li>
                                <div class="article-post" style="height: 60px;font-size:16px;">
                                    <div class="" style="float:right;">
                                        商品数量：<span id='goods_qty' style="color:red;">0</span><br>
                                        商品金额：￥<span id='goods_amount' style="text-decoration:line-through;">0.00</span><br>
                                        支付金额：￥<span id='order_amount' style="color:red;">0.00</span><br>
                                    </div>
                                </div>
                            </li>
                            <li style="text-align:center;">
                                <button id='checkOutOrder' class="btn btn-success" type="submit">预览订单</button>
                            </li>
                        </ul>
                    </div>
                </div>

            </div>
        </div>


    </div>


</div>
</block>

<block name="js_content">
<script>
    DealerCartPage = {
        'BindEvent': function(){
            //选择地址
            $(".biz_address_div").bind('click', function(){
                var address_id = $(this).attr('address_id');
                $('#address').attr('select_address_id', address_id);

                $(".biz_address_div").find('.alert').removeClass('alert-error');
                $(".biz_address_div").find('.alert').addClass('alert-success');
                $(".biz_address_div").find('.addressSelect').text('未选择');


                $(this).find('.alert').removeClass('alert-success');
                $(this).find('.alert').addClass('alert-error');

                $(this).find('.addressSelect').text('已选择');

                return false;
            });


            //绑定加减号
            $('.icon-plus').bind("click", function(){
                var curr_qty	= parseInt($(this).parents('li').find('input').val());
                var new_qty		= curr_qty + 1;
                $(this).parents('li').find('input').val(new_qty);
                DealerCartPage.ReclacAmnount();
                return false;
            });

            //绑定加减号, .icon-minus
            $('.icon-minus').bind("click", function(){
                var curr_qty	= parseInt($(this).parents('li').find('input').val());
                var new_qty		= curr_qty - 1;
                if(new_qty < 0){
                    new_qty = 0;
                }
                $(this).parents('li').find('input').val(new_qty);
                DealerCartPage.ReclacAmnount();
                return false;
            });

            var before=1;

            $('.qty').bind('keydown',function(){
                before=$(this).val();
            });

            $('.qty').bind('keyup',function(){
                if(isNaN($(this).val())){
                    alert('不是数字');
                    $(this).val(before);
                    return;
                }
                DealerCartPage.ReclacAmnount();
            });




            //预览订单
            $('#checkOutOrder').bind('click',function(){
                var dealer_id = $('#biz_dealer').attr('dealer_id');
                if(dealer_id==''){
                    alert('请加载经销商信息');
                    return;
                }

                var select_address_id = $('#address').attr('select_address_id');

                if(select_address_id==''){
                    alert('地址信息未选择');
                    return;
                }

                var totalQty=$('#goods_qty').text();

                if(totalQty==0){
                    alert('商品未选择');
                    return;
                }

                var sku_list = Array();
                $('.recent-posts li').each(function(){
                    if($(this).find('.qty').size()==0){
                        return true;
                    }
                    var sku_id	= $(this).find('.qty').attr('sku_id');
                    var qty		= $(this).find('.qty').val();
                    sku_list.push(sku_id + "," + qty);
                });
                var sku_list_str = sku_list.join('|');

                var checkResult = DealerService.CheckDealerMinSalePrice(dealer_id,sku_list_str);
                if(checkResult.IsSuccess==0){
                    alert(checkResult.ErrorMsg);
                    return;
                }
                var docHeight = document.documentElement.clientHeight;


                window.location.href = '/Dealer/dealerOrderCheckout?dealer_id='+dealer_id+
                        '&select_address_id='+select_address_id+
                        '&sku_list_str='+sku_list_str;
            });


        },
        //购物车计算
        'ReclacAmnount':function(){
            var goods_qty		= 0;
            var goods_amount	= 0;
            var order_amount	= 0;
            $('.recent-posts li').each(function(){
                if($(this).find('.qty').size()==0){
                    return true;
                }

                var sale_price		= parseFloat($(this).find('.sale_price').text());
                var discount_price	= parseFloat($(this).find('.discount_price').text());
                var qty				= parseInt($(this).find('.qty').val());
                var is_rebate	= $(this).find('.qty').attr('is_rebate');

                if(is_rebate==0){
                    discount_price = sale_price;
                }
                goods_qty	= goods_qty + qty;
                goods_amount= goods_amount + sale_price*qty;
                order_amount= order_amount + discount_price*qty;
            });

            $('#goods_qty').text(goods_qty);
            $('#goods_amount').text(goods_amount.toFixed(2));
            $('#order_amount').text(order_amount.toFixed(2));
        },

    };


    $(document).ready(function(){
        DealerCartPage.BindEvent();
    });

</script>
</block>